package net.huashitong.oversee.web;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.JqGrid;
import net.huashitong.Project.responseModel.NodeNewschedulesDataModel;
import net.huashitong.Project.service.ExportService;
import net.huashitong.node.filter.NodeNewschedulesFilter;
import net.huashitong.user.entity.BnpUser;
import net.huashitong.user.filter.BnpUserFilter;
import net.huashitong.user.service.BnpUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/reportForm")
public class ReportFormCtrl extends JsonBaseController {
    @Override
    protected String getView(String s) {
        return "/modules/reportForm/" + s;
    }

    @Autowired
    private BnpUserService bnpUserService;

    @Autowired
    private ExportService exportService;

    @RequestMapping(method = RequestMethod.GET)
    public String initPage() {
        return getView("query");
    }


    //初始化数据
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST)
    public JqGrid query(@ModelAttribute NodeNewschedulesFilter filter) {
        List<NodeNewschedulesDataModel> list = exportService.queryNodeNewschedulesData(filter);
        return coverJqGrid(filter, list);
    }

    @RequestMapping("/filter")
    public String filter(@ModelAttribute BnpUserFilter filter, Model model) {
        //查询用户单位、角色
        List<BnpUser> userList = bnpUserService.getUserInfoUsePage(filter);
        model.addAttribute("userList", userList);
        return getView("filter");
    }

}
